/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.irssproject.app.entitats;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author adria
 */
@Entity
@Table(name = "usuaris")
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")})
public class User implements Serializable {

    private static final long serialVersionUID = 1L;
    private Long id;
    private String login;
    private String password;
    private String email;
    private String name;
    private String place;
    private Collection<Subscription> subscripcions;

    public User() {
    }

    public User(Long idusuari) {
        this.id = idusuari;
    }

    public User(Long idusuari, String login, String password, String email) {
        this.id = idusuari;
        this.login = login;
        this.password = password;
        this.email = email;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idusuari")
    public Long getId() {
        return id;
    }

    public void setId(Long idusuari) {
        this.id = idusuari;
    }

    @Basic(optional = false)
    @Column(name = "login")
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    @Basic(optional = false)
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic(optional = false)
    @Column(name = "email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "nom")
    public String getName() {
        return name;
    }

    public void setName(String nom) {
        this.name = nom;
    }

    @Column(name = "residencia")
    public String getPlace() {
        return place;
    }

    public void setPlace(String residencia) {
        this.place = residencia;
    }
    
    /**
     * @return the subscripcions
     */
    @OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
    public Collection<Subscription> getSubscripcions() {
        return subscripcions;
    }

    /**
     * @param subscripcions the subscripcions to set
     */
    public void setSubscripcions(Collection<Subscription> subscripcions) {
        this.subscripcions = subscripcions;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.irssproject.app.entitats.Usuari[idusuari=" + id + "]";
    }

}
